<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility"%>
<%@ include file="/public/header.jsp"%>
<%
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
%>
<html>
	<head>
		<title>公共费用报销申请</title>
	<script type="text/javascript">
	jQuery(document).ready(function() {
		$("#company_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=8',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
		jQuery("#user_name").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
		});
		
		jQuery("#table").datagrid({
			title:"公共费用报销申请",
			iconCls:'icon-save',
			loadMsg:'正在加载数据，请稍后......',
			url:'<%=contextPath %>/springMVC/finance/listPageFinanceCommons1',
			rownumbers:true,
			fitColumns:true,
			nowrap:false,
			idField:'id',
			frozenColumns:[[
			      {title:'主键',field:'id',hidden:true}
			]],
			columns:[[
				{title:'日期',field:'operation_time',width:100,align:'center'},
				{title:'申请人',field:'user_name',width:100,align:'center'},
				{title:'金额',field:'money',width:100,align:'center'},
				{title:'所属公司',field:'name',width:100,align:'center'},
				{title:'摘要',field:'summary',width:200,align:'center'},
				{title:'确定承担部门',field:'is_all',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					if(rowData.is_all == 0){
						return "确定";
					}
					return "不确定";
				}},
				{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
				{title:'是否已放款',field:'has_finished',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "已放款";
						}
						return "未放款";
					}},
				{title:'详情操作',field:'opMore',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editFC('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteFC('"+rowData.id+"');\"/>";
						}
						if(rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editFC('"+rowData.id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;";
						}
						if(rowData.status == 1 || rowData.status == 3){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.FINCEN_COMMONS%>")+"','"+rowData.id+"');\"/>&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewFC('"+rowData.id+"');\"/>";
						}
	                    return str;
				}}
			]],
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			onLoadSuccess:function(rtJson){
				if(rtJson.rtState== '1')
				{
					$.messager.alert('提示',rtJson.rtMsrg);
				}
			}
		});
	});
	
	function add(){
		openDialogResize("<%=contextPath %>/springViews/finance/addOrEditFinanceCommons.jsp?callback=rtCallBack",1000, 800);
	}
	
	function editFC(id){
		openDialogResize("<%=contextPath %>/springViews/finance/addOrEditFinanceCommons.jsp?callback=rtCallBack&id="+id,1000, 800);
	}
	function viewFC(id){
		openDialogResize("<%=contextPath %>/springViews/finance/addOrEditFinanceCommons.jsp?isShow=1&id="+id,1000, 800);
	}
	function deleteFC(id){
		$.ajax({
			type:'POST',
			url:'<%=contextPath%>/springMVC/finance/deleteFinanceCommons?id='+id,
			success:function(rtJson){
				if(rtJson.rtState == 0){
					$.messager.alert("提示",rtJson.rtMsrg);
					$('#table').datagrid('reload');
				}else{
					$.messager.alert("提示",rtJson.rtMsrg);
				}
			}
			
		});
		
	}
	
	function rtCallBack(){
		$('#table').datagrid('reload');
	}
		
	function shenpi(obj,id){
    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
      var flowBusinessUrl="<%=contextPath %>/springViews/finance/addOrEditFinanceCommons.jsp?id="+id+"&isShow=1";
      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.FINCEN_COMMONS%>")+"&businessId="+id;
      $(obj).hide();
      $.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
					dataType:"JSON",
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							openDialogResize(rtJson.rtData.url,1000,800);
						}else{
							warningInfo(rtJson.rtMsrg);
						}
						$(obj).show();
					}
				});
       
    } 
		function doSearch() {
			var start_time=jQuery('#start_time').datebox('getValue');  
			var end_time=jQuery('#end_time').datebox('getValue'); 
			var user_name=jQuery('#user_name').val();
			var company_id = $('#company_id').combotree('getValue');
			jQuery('#table').datagrid('load', {
				start_time:start_time,
				end_time:end_time,
				user_name:user_name,
				company_id:company_id
			});
		}
		  function ExcelOut(){
			 	var searchValue =jQuery('#searchValue').val();
				var company_id = jQuery("#company_id").combotree('getValue');
				var user_name=jQuery('#user_name').val();
				var param = "searchValue="+encodeURIComponent(searchValue)+"&company_id="+company_id+"&user_name="+user_name;
				window.open('<%=contextPath %>/springMVC/excel/listFinanceCommonsExcel?'+param);
			}
	</script>
	</head>
	<body style="height:97%">
			<div id="table"  data-options="toolbar:'#tb',fit:true"></div>  
				<div id="tb" style="padding:3px;height:auto">
				<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add();">添加申请</a>
			</div>
			<div align="right">
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
				申请人：<input type="text" id="user_name" name="user_name"   style="width:100px">
				所属公司：<input type="text" id="company_id" name="company_id"   style="width:100px">
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
				<input type='button'  style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-excel' title='导出Excel' onclick='ExcelOut()'/>
			</div>
		</div>
	</body>
</html>